package designPattern.filter.tomcatFilter;

import java.util.ArrayList;
import java.util.List;

public class FilterChain implements Filter {

	List<Filter> filters = new ArrayList<Filter>();// 数组形式的责任链，他通过一个index来驱动请求向下执行
	int index = -1;

	public FilterChain add(Filter f) {
		filters.add(f);
		return this; // 返回this的好处是：可以链式编程
	}

	@Override
	public void doFilter(Request request, Response response,
			FilterChain filterChain) {
		filters.get(++index).doFilter(request, response, filterChain);
	}

}
